home *** CD-ROM | disk | FTP | other *** search
/ Best of www.BestZips.com (Collector's Edition) / Best of WWW.BESTZIPS.COM Collector's Edition (JCSM Shareware) (JCS Marketing).ISO / prgtools / euphor14.zip / INSTALL.EX < prev    next >
Text File  |  1996-06-02  |  14KB  |  487 lines

  1.         -----------------------------------
  2.         --  Program to Install Euphoria  --
  3.         --  (see install.doc)            --
  4.         -----------------------------------
  5.  
  6. include file.e
  7. include graphics.e
  8. include wildcard.e
  9.  
  10. constant KEYBOARD = 0, SCREEN = 1
  11. constant SUCCESS = 1, FAILURE = 0, NO_EDIT = 2
  12. constant TRUE = 1, FALSE = 0
  13. constant CLEAR = 0, NO_CLEAR = 2
  14.  
  15.     -------------------------------------------------
  16.     -- Subdirectory structure for Euphoria files.  --
  17.     -------------------------------------------------
  18.  
  19. constant file_list = {
  20.   {"BIN", 
  21.    "BIN.DOC", "SYNCOLOR.E", "LINES.BAT", "LINES.EX", "EPRINT.EX", "GURU.BAT",
  22.    "GURU.EX", "EPRINT.BAT", "ED.BAT", "ED.EX", "KEYWORDS.E", "SB.BAT", 
  23.    "CDGURU.BAT", "SEARCH.EX", "SEARCH.BAT", "FREQ.EX", "BIND.BAT", 
  24.    "SHROUD.BAT", "EX.EXE", "ASCII.EX", "ASCII.BAT", "WHERE.EX", "WHERE.BAT", 
  25.    "BIND.EX", "KEY.BAT", "KEY.EX"},
  26.   
  27.   {"DOC", 
  28.    "WHAT2DO.DOC", "ED.DOC", "REFMAN.DOC", "LIBRARY.DOC", "C.DOC", "BASIC.DOC", 
  29.    "REGISTER.DOC", "RELNOTES.DOC", "ORDER.FRM", "INSTALL.DOC", "WEB.DOC",
  30.    "TROUBLE.DOC"},
  31.  
  32.   {"DEMO",
  33.    "BITMAP.EX", "DEMO.DOC", "PLOT3D.EX", "ANIMAL.EX", "ALLSORTS.EX",  
  34.    "EXAMPLE.EX", "SB.EX", "SELECT.E", "TTT.EX", "SIMPLE.EX", "LEARN.EX",
  35.    "WIRE.EX", "SANITY.EX", "MOUSE.EX", "MSET.EX", "QUEENS.EX", "BUZZ.EX",
  36.    "POLYGON.EX", "CALLMACH.EX", "MYDATA.EX", "STEREO.EX", "PICTURE",
  37.    "DOSINT.EX"},
  38.  
  39.   {"DEMO\\LANGWAR", 
  40.    "LW.DOC", "LW.SUM", "WEAPONS.E", "SCREEN.E", "COMMANDS.E", "DAMAGE.E",  
  41.    "DISPLAY.E", "EMOVE.E", "ENEMY.E", "SCHED.E", "VARS.E", "SOUNDEFF.E",  
  42.    "LW.EX"},   
  43.  
  44.   {"DEMO\\BENCH", 
  45.    "BENCH.DOC", "SHELL.EX", "SHELL.BAS", "DATABASE.EX", "DATABASE.BAS", 
  46.    "SIEVE.EX", "SIEVE.BAS", "SEQUENCE.EX", "SEQUENCE.BAS", "FILESORT.EX"},   
  47.   
  48.   {"INCLUDE", 
  49.    "GRAPHICS.E", "SORT.E", "GET.E", "MOUSE.E", "FILE.E", "MACHINE.E",
  50.    "WILDCARD.E", "IMAGE.E"}  
  51. }
  52.  
  53. object move_command
  54. move_command = "c:\\dos\\move.exe " -- DOS 6
  55. if atom(dir(move_command)) then
  56.     move_command = "c:\\windows\\command\\move.exe " -- DOS 7
  57.     if atom(dir(move_command)) then
  58.     move_command = -1 -- assume no move command
  59.     end if
  60. end if
  61.  
  62. sequence vc
  63. vc = video_config()
  64.  
  65. integer color_monitor
  66. color_monitor = vc[VC_COLOR]
  67.  
  68. procedure the_end()
  69. -- exit install
  70.     puts(SCREEN, "\nPress Enter...\n")
  71.     if atom(gets(0)) then
  72.     end if
  73.     abort(0)
  74. end procedure
  75.  
  76. procedure fore_color(integer c)
  77. -- change foreground color
  78.     if color_monitor then
  79.     text_color(c)
  80.     end if
  81. end procedure
  82.  
  83. procedure move(sequence source, sequence dest)
  84. -- move one file into a directory
  85.  
  86.     puts(SCREEN, "    " & source & '\n')
  87.  
  88.     -- MOVE (DOS 6,7)
  89.     if sequence(move_command) then
  90.     system(move_command & source & ' ' & dest & " > NUL", NO_CLEAR)
  91.     if sequence(dir(dest & "\\" & source)) then
  92.         return
  93.     else
  94.         puts(SCREEN, "OK - no MOVE command - use COPY instead ...\n")
  95.         move_command = -1 -- doesn't work
  96.     end if
  97.     end if
  98.  
  99.     -- COPY (DOS 5 or earlier)
  100.     system("copy " & source & ' ' & dest & " > NUL", NO_CLEAR)
  101.     if sequence(dir(dest & "\\" & source)) then
  102.     system("del " & source, NO_CLEAR)
  103.     else
  104.     -- copy failed
  105.     puts(SCREEN, "Unable to copy " & source & 
  106.              " to " & dest & " subdirectory\n")
  107.     if sequence(dir(source)) and sequence(dir("euphor14.zip")) then
  108.         puts(SCREEN, "Perhaps you can try again without the .zip file\n")
  109.     end if
  110.     end if
  111. end procedure
  112.  
  113. procedure moveall()
  114. -- move all files into the correct subdirectories
  115.     sequence command
  116.     integer f
  117.  
  118.     f = open("bin\\ex.exe", "rb")
  119.     if f != -1 then
  120.     close(f)
  121.     puts(SCREEN, "Subdirectory structure has been set up\n")
  122.     return
  123.     end if
  124.     puts(SCREEN, "Creating Euphoria Subdirectories ...\n\n")
  125.     for i = 1 to length(file_list) do
  126.     command = "mkdir " & file_list[i][1]
  127.     puts(SCREEN, command & '\n')
  128.     system(command, NO_CLEAR) 
  129.     for j = 2 to length(file_list[i]) do
  130.         move(file_list[i][j], file_list[i][1])
  131.     end for
  132.     -- Only Complete Edition has this file:
  133.     if compare(file_list[i][1], "BIN") = 0 then
  134.         if sequence(dir("PDEX.EXE")) then
  135.         move("PDEX.EXE", "BIN")
  136.         end if
  137.     end if
  138.     end for
  139.     -- "how-to-unzip" file not needed anymore:
  140.     system("del unzip.doc", NO_CLEAR) 
  141. end procedure
  142.  
  143. function setupdir()
  144. -- set up subdirectories 
  145.     moveall()
  146.     if atom(dir("bin\\ex.exe")) then
  147.     puts(SCREEN, "Subdirectory set up failed - see install.doc\n")
  148.     return FAILURE
  149.     end if
  150.     return SUCCESS
  151. end function
  152.  
  153. procedure rename_it()
  154.     puts(SCREEN, 
  155.      "Please remove it or rename it before installing a new version.\n")
  156. end procedure
  157.  
  158. function copy_to_hard_disk(integer drive)
  159. -- copy Euphoria files to EUPHORIA directory 
  160.     sequence eu_dir, rename_dir
  161.     integer rename_letter
  162.  
  163.     eu_dir = drive & ":\\EUPHORIA"
  164.  
  165.     if compare(upper(current_dir()), eu_dir) = 0 then
  166.     -- we're in EUPHORIA directory already - just set up subdirectories
  167.     return setupdir() 
  168.     end if
  169.  
  170.     if sequence(dir(eu_dir)) then
  171.     puts(SCREEN,
  172.     "An existing EUPHORIA directory was found on drive " & drive & ".\n")
  173.     if sequence(move_command) then
  174.         rename_letter = 'F'
  175.         while rename_letter <= 'Z' do
  176.         rename_dir = drive & ":\\" & rename_letter & "UPHORIA"
  177.         if atom(dir(rename_dir)) then
  178.             exit
  179.         end if
  180.         rename_letter = rename_letter + 1
  181.         end while
  182.         if rename_letter <= 'Z' then
  183.         system(move_command & eu_dir & ' ' & rename_dir & "> NUL", NO_CLEAR)
  184.         if sequence(dir(rename_dir)) then
  185.             puts(SCREEN,"It has been renamed as " & rename_dir & "\n\n")
  186.         else
  187.             rename_it()
  188.             return FAILURE
  189.         end if
  190.         else
  191.         rename_it()
  192.         return FAILURE
  193.         end if
  194.     else
  195.         rename_it()
  196.         return FAILURE
  197.     end if
  198.     end if
  199.  
  200.     puts(SCREEN, "The EUPHORIA files will now be copied to " & eu_dir & '\n')
  201.     puts(SCREEN, "    * Press Enter to start copying. [recommended action]\n")
  202.     puts(SCREEN, "    * or type ! to abort.\n")
  203.  
  204.     if find('!', gets(KEYBOARD)) then
  205.     puts(SCREEN, "\ninstallation aborted - try again later\n")
  206.     the_end()
  207.     end if
  208.  
  209.     system("mkdir " & eu_dir, NO_CLEAR)
  210.     if atom(dir(eu_dir)) then
  211.     puts(SCREEN, "\n\nCouldn't create " & eu_dir & ".\n")
  212.     puts(SCREEN, "See install.doc\n")
  213.     return FAILURE
  214.     end if
  215.  
  216.     -- copy all files to EUPHORIA directory
  217.     system("xcopy *.* " & eu_dir, CLEAR)
  218.     if atom(dir(eu_dir & "\\EX.EXE")) or 
  219.        atom(dir(eu_dir & "\\BIND.BAT")) then -- BIND.BAT is last file xcopied
  220.     puts(SCREEN, "xcopy failed - trying copy\n")
  221.     system("copy *.* " & eu_dir, CLEAR)
  222.     if atom(dir(eu_dir & "\\EX.EXE")) or 
  223.        atom(dir(eu_dir & "\\BIND.BAT")) then 
  224.         puts(SCREEN, "copy failed - see install.doc\n")
  225.         return FAILURE
  226.     end if
  227.     end if
  228.  
  229.     -- copy worked, now cd to EUPHORIA
  230.     system(drive & ':', NO_CLEAR)
  231.     system("cd " & eu_dir, NO_CLEAR)
  232.     if compare(upper(current_dir()), eu_dir) != 0 then
  233.     puts(SCREEN, "cd failed - see install.doc\n")
  234.     return FAILURE
  235.     end if
  236.  
  237.     -- cd worked, now set up subdirectories
  238.     return setupdir() 
  239.  
  240. end function
  241.  
  242. function Yes()
  243. -- return TRUE if answer is "y"
  244.     sequence answer
  245.     
  246.     while TRUE do
  247.     answer = upper(gets(KEYBOARD))
  248.     puts(SCREEN, '\n')
  249.     if find('Y', answer) then
  250.         return TRUE
  251.     elsif find('N', answer) then
  252.         return FALSE
  253.     else
  254.         puts(SCREEN, "Please answer with y or n: ")
  255.     end if
  256.     end while
  257. end function
  258.  
  259. constant MAX_PATH = 127 - length("C:\\EUPHORIA\\BIN; ")
  260.  
  261. function edit_auto_exec(integer drive)
  262. -- edit the autoexec.bat file
  263. -- add to the PATH, set EUDIR
  264.     integer path_found, q, auto_exec_no, p, white, semi_pos
  265.     sequence path, auto_exec, auto_name, base_name, answer, set_line
  266.     object line
  267.  
  268.     path = getenv("PATH")
  269.     if sequence(path) then
  270.     if match("EUPHORIA\\BIN", path) then
  271.         puts(SCREEN, "\nYour current PATH already has EUPHORIA\\BIN\n")
  272.         return NO_EDIT
  273.     end if
  274.     if length(path) >= MAX_PATH then
  275.         puts(SCREEN, "\nYour current PATH is too long to add EUPHORIA\\BIN\n")
  276.         puts(SCREEN, "Perhaps you can remove a directory from it.\n")
  277.         return FAILURE
  278.     end if
  279.     end if
  280.     puts(SCREEN, "\n\nEditing autoexec.bat ...\n")
  281.     base_name = ":\\autoexec.bat"
  282.     auto_name = "C" & base_name  -- try C first
  283.     auto_exec_no = open(auto_name, "r")
  284.     while auto_exec_no = -1 do
  285.     puts(SCREEN, "Couldn't open " & auto_name & '\n')
  286.     puts(SCREEN, "On what drive is your autoexec.bat file?\n")
  287.     puts(SCREEN, "Type a letter: (! to abort)\n")
  288.     answer = gets(KEYBOARD)
  289.     if find('!', answer) then
  290.         puts(SCREEN, "\ninstallation aborted - see install.doc Part B\n")
  291.         the_end()
  292.     end if
  293.     auto_name = answer[1] & base_name
  294.     auto_exec_no = open(auto_name, "r")
  295.     end while
  296.     -- read in the entire autoexec.bat
  297.     auto_exec = {}
  298.     path_found = 0
  299.     while TRUE do
  300.     line = gets(auto_exec_no)
  301.     if atom(line) then
  302.         exit
  303.     end if
  304.     p = match("PATH", upper(line))
  305.     if p then
  306.         -- line contains the word "PATH" in upper or lower case
  307.         -- at position p
  308.         white = TRUE
  309.         q = p - 1
  310.         while q >= 1 do
  311.         if not find(line[q], " \t") then
  312.             -- non whitespace - only "SET" is allowed
  313.             if q >= 3 then
  314.             if compare("SET", upper(line[q-2..q])) = 0 then
  315.                 q = q - 2
  316.             else
  317.                 white = FALSE
  318.                 exit
  319.             end if
  320.             else
  321.             white = FALSE
  322.             exit
  323.             end if
  324.         end if
  325.         q = q - 1
  326.         end while
  327.  
  328.         if white and find(line[p+4], " \t=") then
  329.         -- this is a PATH line
  330.         path_found = path_found + 1
  331.         if path_found = 1 then
  332.             -- only change the first one encountered
  333.             set_line = "SET EUDIR=" & drive & ":\\EUPHORIA\n"
  334.             auto_exec = append(auto_exec, set_line)
  335.             if match(drive & ":\\EUPHORIA\\BIN", upper(line)) then
  336.             -- its already there
  337.             puts(SCREEN, "PATH already has " & drive & 
  338.                      ":\\EUPHORIA\\BIN\n")
  339.             close(auto_exec_no)
  340.             return NO_EDIT
  341.             end if
  342.             if length(line) > MAX_PATH then
  343.             -- line is too long (MS-DOS restriction)
  344.             puts(SCREEN, 
  345.             "Your PATH line is too long to add EUPHORIA\\BIN\n")
  346.             puts(SCREEN, 
  347.             "Perhaps you can delete a directory from it.\n")
  348.             puts(SCREEN, 
  349.             "No changes were made to your autoexec.bat file.\n")
  350.             close(auto_exec_no)
  351.             return FAILURE
  352.             end if
  353.             semi_pos = find(';', line)
  354.             if semi_pos = 0 then
  355.             semi_pos = length(line)
  356.             line = line[1..length(line)-1] & ";\n"
  357.             end if
  358.             -- add EUPHORIA\BIN to path
  359.             puts(SCREEN, "Changing this line:\n")
  360.             fore_color(2)
  361.             puts(SCREEN, line)
  362.             fore_color(7)
  363.             puts(SCREEN, "to:\n")
  364.             fore_color(2)
  365.             puts(SCREEN, line[1..semi_pos])
  366.             fore_color(4)
  367.             puts(SCREEN, drive & ":\\EUPHORIA\\BIN;")
  368.             fore_color(2)
  369.             puts(SCREEN, line[semi_pos+1..length(line)])
  370.             line = line[1..semi_pos] &
  371.                drive & ":\\EUPHORIA\\BIN;" &
  372.                line[semi_pos+1..length(line)]
  373.             fore_color(7)
  374.             puts(SCREEN, "and inserting the following line:\n")
  375.             fore_color(4)
  376.             puts(SCREEN, set_line)
  377.             fore_color(7)
  378.         end if
  379.         end if
  380.     end if
  381.     auto_exec = append(auto_exec, line)
  382.     end while
  383.     close(auto_exec_no)
  384.  
  385.     if not path_found then
  386.     puts(SCREEN, "The PATH command could not be found.\n")
  387.     puts(SCREEN, "No changes were made to your autoexec.bat.\n")
  388.     return FAILURE
  389.     else
  390.     -- write out the new autoexec.bat
  391.     puts(SCREEN, 
  392.     "Is it OK to make these changes to your autoexec.bat file? (y or n) \n")
  393.     puts(SCREEN, "-----> ") 
  394.     if not Yes() then
  395.         return FAILURE
  396.     end if
  397.     if path_found = 2 then
  398.         puts(SCREEN, "One other \"PATH\" line was found but not changed.\n") 
  399.         puts(SCREEN, "Please take a look at it.\n")
  400.     elsif path_found > 2 then
  401.         printf(SCREEN, "%d other \"PATH\" lines were found but not changed.\n",
  402.         path_found - 1)
  403.         puts(SCREEN, "Please take a look at them.\n")
  404.     end if
  405.     auto_exec_no = open(auto_name, "w")
  406.     if auto_exec_no = -1 then
  407.         puts(SCREEN, "Couldn't write out the new autoexec.bat!\n")
  408.         puts(SCREEN, "Your autoexec.bat file is read-only.\n")
  409.         return FAILURE
  410.     end if
  411.     for i = 1  to length(auto_exec) do
  412.         puts(auto_exec_no, auto_exec[i])
  413.     end for
  414.     close(auto_exec_no)
  415.     end if
  416.     return SUCCESS
  417. end function
  418.  
  419. procedure install()
  420. -- main routine for Euphoria installation
  421.     integer drive
  422.     integer edit_status
  423.     sequence answer
  424.  
  425.     clear_screen()
  426.     fore_color(5)
  427.     puts(SCREEN, "\nEuphoria")
  428.     fore_color(7)
  429.     puts(SCREEN, " Installation Program\n\n")
  430.  
  431.     if atom(dir("EX.EXE")) then
  432.     puts(SCREEN, 
  433.     "All files must be together in one directory to run install.\n")
  434.     return
  435.     end if
  436.  
  437.     puts(SCREEN, "On which drive do you want to put the EUPHORIA directory?\n")
  438.     puts(SCREEN, "Type the drive letter, or just hit Enter for drive C\n")
  439.     puts(SCREEN, "-----> ")
  440.  
  441.     answer = upper(gets(KEYBOARD))
  442.  
  443.     while answer[1] = ' ' or answer[1] = '\t' do
  444.     answer = answer[2..length(answer)]
  445.     end while
  446.  
  447.     drive = answer[1]
  448.     if drive < 'A' or drive > 'Z' then
  449.     drive = 'C'
  450.     end if
  451.  
  452.     puts(SCREEN, '\n')
  453.  
  454.     if copy_to_hard_disk(drive) = FAILURE then
  455.     return
  456.     end if
  457.  
  458.     edit_status = edit_auto_exec(drive)
  459.  
  460.     if edit_status = FAILURE then
  461.     puts(SCREEN, 
  462.     "To complete the install you should edit autoexec.bat manually.\n") 
  463.     puts(SCREEN, "See doc\\install.doc - Manual Procedure Part B\n")
  464.     return
  465.     end if
  466.  
  467.     puts(SCREEN, "\nInstall Completed.\n")
  468.     if edit_status = NO_EDIT then
  469.     puts(SCREEN, 
  470.     "You might start by looking at readme.doc or doc\\what2do.doc\n")
  471.     else
  472.     puts(SCREEN, "After pressing Enter, you should exit Windows, ")
  473.     puts(SCREEN, "remove any floppy disks,\nthen press Control-Alt-Delete")
  474.     puts(SCREEN, " to reboot your machine. ")
  475.     puts(SCREEN, "This will set\nyour PATH and EUDIR variables.\n\n")
  476.     puts(SCREEN, "When the system is back up you might start\n")  
  477.     puts(SCREEN, "by looking at readme.doc or doc\\what2do.doc.\n")
  478.     puts(SCREEN, 
  479.     "The Euphoria editor, ed, will be available - see doc\\ed.doc.\n")
  480.     end if
  481.     puts(SCREEN, "\n\t\tEnjoy!\n")
  482. end procedure
  483.  
  484. install()
  485. the_end()
  486.  
  487.